//
//  ZM_Banner_CollectionReuseV.m
//  YYFMMall
//
//  Created by MAC on 2019/12/20.
//  Copyright © 2019 YuYou1. All rights reserved.
//

#import "ZM_Banner_CollectionReuseV.h"

@interface ZM_Banner_CollectionReuseV()<SDCycleScrollViewDelegate>


@end

@implementation ZM_Banner_CollectionReuseV
#pragma mark - 赋值
- (void)setImgArr:(NSArray *)imgArr{
    _imgArr = imgArr;
    _cycleScrollView.imageURLStringsGroup = imgArr;
    _cycleScrollView.infiniteLoop = imgArr.count <= 1?NO:YES;
    if (!self.numLbl.hidden&&imgArr.count > 1) {
        _numLbl.text = [NSString stringWithFormat:@"1/%ld ",imgArr.count];
    }
}

-(void)setBannerType:(BannerType)bannerType{
    _bannerType = bannerType;
    switch (bannerType) {
        case bannerTypeDefault:{
            self.cycleScrollView.currentPageDotColor = kMainColor;
            self.cycleScrollView.pageDotColor = kBgColor;
            self.cycleScrollView.showPageControl = YES;
            self.cycleScrollView.delegate = self;
            self.cycleScrollView.hidesForSinglePage = YES;
            self.cycleScrollView.autoScroll = YES;
            self.cycleScrollView.infiniteLoop = YES;
            self.cycleScrollView.backgroundColor = kHexColor(0xF6F6F6);
        }break;
        case bannerTypeShowNum:{
            self.numLbl.hidden = NO;
            self.cycleScrollView.showPageControl = NO;
            self.cycleScrollView.delegate = self;
            self.cycleScrollView.hidesForSinglePage = YES;
            self.cycleScrollView.autoScroll = NO;
            self.cycleScrollView.infiniteLoop = YES;
            self.cycleScrollView.backgroundColor = kHexColor(0xF6F6F6);
        }break;
        default:
            break;
    }
}

#pragma mark -Methods


#pragma mark - Intial
-(instancetype)initWithCoder:(NSCoder *)aDecoder{
    if (self = [super initWithCoder: aDecoder]) {
        [self setUpBaseData];
        [self setUpUI];
    }
    return self;
}

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self setUpBaseData];
        [self setUpUI];
    }
    return self;
}

///基本数据配置
-(void)setUpBaseData{
    
}

///控件添加
-(void)setUpUI{
    [self bgV];
    [self cycleScrollView];
    [self numLbl];
}


#pragma mark- SDCycleScrollViewDelegate
/** 点击图片回调 */
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
    !self.cycleScrollViewSelectBlock?:self.cycleScrollViewSelectBlock(index);
}
/** 图片滚动回调 */
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didScrollToIndex:(NSInteger)index{
    if (!self.numLbl.hidden&&self.imgArr.count > 1) {
        self.numLbl.text = [NSString stringWithFormat:@"%ld/%ld ",index + 1,self.imgArr.count];
    }
}

#pragma mark - 布局
-(void)layoutSubviews{
    [super layoutSubviews];
    
}

#pragma mark - lazyload
-(UIView *)bgV{
    if (!_bgV) {
        _bgV = [UIView new];
        _bgV.hidden = YES;
        _bgV.backgroundColor = kHexColor(0xFAFAFA);
        [self addSubview:_bgV];
        [_bgV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(15);
            make.right.mas_equalTo(-15);
            make.bottom.top.mas_equalTo(0);
        }];
    }
    return _bgV;
}

-(SDCycleScrollView *)cycleScrollView{
    if (!_cycleScrollView) {
        _cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage:kImage(KDefBannerIcon)];
        _cycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleToFill;
        _cycleScrollView.currentPageDotColor = kMainColor;
        _cycleScrollView.pageDotColor = kBgColor;
        _cycleScrollView.showPageControl = YES;
        _cycleScrollView.delegate = self;
        _cycleScrollView.hidesForSinglePage = YES;
        _cycleScrollView.autoScroll = YES;
        _cycleScrollView.infiniteLoop = YES;
        _cycleScrollView.backgroundColor = kHexColor(0xF6F6F6);
        [self addSubview:_cycleScrollView];
        [_cycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_equalTo(0);
        }];
    }
    return _cycleScrollView;
}

-(UILabel *) numLbl {
    if (!_numLbl) {
        _numLbl = [UILabel new];
        _numLbl.backgroundColor = kBlackColor;
        _numLbl.font = kMediumFont(11);
        _numLbl.textColor = kWhiteColor;
        _numLbl.textAlignment = NSTextAlignmentCenter;
        _numLbl.hidden = YES;
        _numLbl.alpha = 0.5;
        [self addSubview:_numLbl];
        [_numLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self).offset(10);
            make.bottom.mas_equalTo(self).offset(-15);
            make.size.mas_equalTo(kSize(55, 20));
        }];
        [ZMSpeedy zm_changeControl:_numLbl cornerRadius:10 borderWidth:0 borderColor:nil mask:YES];
    }
    return _numLbl;
}

-(void)dealloc{
    
}
@end
